<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
 <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/cookie.js"></script>
</head>
<body>
<div class="x-nav">
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="${pageContext.request.contextPath}/manager/managerList" title="刷新">
        刷新</a>
    </div>
<div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="L_username" class="layui-form-label">
                  昵称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="username" disabled="" value="${sessionScope.manager.name}" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
                  <span class="x-red">*</span>旧密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="oldPass" name="oldpass" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
                  <input type="hidden" id="oldPass" value="${sessionScope.manager.password}"/>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_pass" class="layui-form-label">
                  <span class="x-red">*</span>新密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="firstPass" name="firstPass" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
                  <br><div class="box">
					   <div class="bg"></div>密码强度：
					     <span class="spans" style='color:f5f5f5'>弱</span>
					</div>
                  
              </div>
              <div class="layui-form-mid layui-word-aux">
                
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
                  <span class="x-red">*</span>确认密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="secondPass" name="secondPass" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn"  id="add-btn">
                  增加
              </button>
          </div>
      </form>
    </div>
    <script type="text/javascript">
	//密码强度设置
	$(document).ready(function() {
		$("#firstPass").keyup(function() {
			var textMax = 16;
			$("#firstPass").attr("maxlength", textMax); //追加最大值
			var boxlen = $(".box").css("width"); //添加width属性
			//alert(boxlen);
			var inputlength = $("#firstPass").val().length; //获取输入值的个数
			var bgwidth = (inputlength / textMax) * parseInt(boxlen);
			//alert(bgwidth);
			$(".bg").css("width", bgwidth);

			if(bgwidth <= 120) //
			{
				$(".bg").css("background-color", "#F00");
				$(".spans").html("<span>弱</span>");
			} else if(120 < bgwidth) {
				if($("#firstPass").val().match(/\d/) && $("#firstPass").val().match(/[a-zA-Z]/)) {
					$(".bg").css("background-color", "#6F3");
					$(".spans").html("<span>强</span>");
				} else {
					$(".bg").css("background-color", "#F90");
					$(".spans").html("<span>中</span>");
				}
			}

		})
	})

    	$("#add-btn").click(function(){
    		var oldPass=$("#oldPass").val();
    		var firstPass=$("#firstPass").val();
    		var secondPass=$("#secondPass").val();
    		var username=$("#username").val();
    		console.log(oldPass+firstPass+secondPass+username);
    		if(firstPass!=secondPass){
    			alert("两次密码不相同");
    		}else{
    			$.ajax({
    				url:"${pageContext.request.contextPath}/changeUserPass",
    				type:"post",
    				dataType:"json",
    				data:{"username":username,"oldpass":oldPass,"firstPass":firstPass,"secondPass":secondPass},
    				success:function(data){
    				}
    				
    				
    				
    			});
    		}
    		
    		
    		return false;
    	})
    	
    	/* layui.use(['form', 'layer'],
   			$("#add-btn").click(function(){
   	    		var oldPass=$("#oldPass").val();
   	    		var firstPass=$("#firstPass").val();
   	    		var secondPass=$("#secondPass").val();
   	    		var username=$("#username").val();
                //监听提交
                form.on('submit(add)',
                function(data) {
                	if(firstPass!=secondPass){
            			alert("两次密码不相同");
            		}else{
            			$.ajax({
            				url:"${pageContext.request.contextPath}/changeUserPass",
            				type:"post",
            				dataType:"json",
            				data:{"username":username,"oldpass":oldPass,"firstPass":firstPass,"secondPass":secondPass},
            				success:function(data){
            				}
            				
            				
            				
            			});
            		}
                    //发异步，把数据提交给php
                    layer.alert("添加成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        x_admin_close();
                        x_admin_father_reload();
                    });
                    return false;
                });

            } */
    </script>
</body>
</html>